import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:shop/model/MyCountModel.dart';
import 'package:shop/router/router_manager.dart';
import 'package:shop/test/SecondHomeScreen.dart';

class FirstHomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [ChangeNotifierProvider.value(value: MyCountModel())],
      child: FirstHome(),
    );
  }
}

class FirstHome extends StatefulWidget {
  @override
  _FirstHomeScreen createState() => _FirstHomeScreen();
}

class _FirstHomeScreen extends State<FirstHome> {
  @override
  Widget build(BuildContext context) {
    var myCountModel = Provider.of<MyCountModel>(context);
    return ChangeNotifierProvider.value(
        value: myCountModel,
        child: Scaffold(
          appBar: AppBar(
            title: Text("FirstHome"),
            actions: <Widget>[
              FlatButton(
                  child: Text("下一页"),
                  onPressed: () =>
                      Navigator.of(context).pushNamed(RouteName.testSecond)),
            ],
          ),
          body: Center(
            child: Text("${myCountModel.count}"),
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: () {
              myCountModel.increment();
            },
            child: Icon(Icons.add),
          ),
        ));
  }
}
